package com.ss.android.push.window.oppo;

import android.content.Context;

import com.bytedance.common.utility.Logger;
import com.ss.android.common.util.MultiProcessSharedProvider;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class m {
    private static m c;
    public Context a;
    public b b;

    private m(Context arg3) {
        this.b = new b(2);
        this.a = arg3.getApplicationContext();
        this.b = new b(OppoPushWindowManager.a(arg3).j);
        this.b();
    }

    public static m a(Context arg2) {
        if (m.c == null) {
            Class v1 = m.class;
            synchronized (v1) {
                if (m.c == null) {
                    m.c = new m(arg2);
                }
            }
        }

        return m.c;
    }

    public final void a() {
        try {
            JSONArray v1 = new JSONArray();
            Map v0_1 = this.b.b();
            if (!v0_1.isEmpty()) {
                Iterator v2 = v0_1.entrySet().iterator();
                while (v2.hasNext()) {
                    Object v0_2 = v2.next();
                    if (v0_2 == null) {
                        continue;
                    }
                    v1.put(((m.a) ((Map.Entry) v0_2).getValue()).a());
                }
            }

            String v0_3 = v1.toString();
            if (v0_3 != null) {
                Logger.d("MessageHandler", "save messageCacheListStr = " + v0_3);
            }

            HashMap v1_1 = new HashMap();
            ((Map) v1_1).put("pop_window_message_cache_list", v0_3);
            com.ss.android.push.window.oppo.a.a(this.a, ((Map) v1_1));
        } catch (Throwable v0) {
            v0.printStackTrace();
        }
    }

    private void b() {
        a v4;
        JSONObject v0_2;
        int v1;
        try {
            String v0_1 = MultiProcessSharedProvider.getMultiProcessSharedPreference(this.a).getString("pop_window_message_cache_list", "");
            if (android.support.design.a.isTextEmpty(v0_1)) {
                return;
            }

            if (v0_1 != null) {
                Logger.d("MessageHandler", "load messageCacheListStr = " + v0_1);
            }

            JSONArray v2 = new JSONArray(v0_1);
            int v3 = v2.length();
            v1 = 0;
            while (true) {
                label_21:
                if (v1 >= v3) {
                    return;
                }
                v0_2 = v2.optJSONObject(v1);
                v4 = new a();
                if (v0_2 == null) {
                } else {
                    v4.a = v0_2.optInt("id");
                    v4.b = v0_2.optInt("type");
                    v4.c = v0_2.optString("obj");
                    v4.d = v0_2.optInt("from");
                    v4.e = v0_2.optString("extra");
                }
                this.b.a(Integer.valueOf(v4.a), v4);
                ++v1;
                continue;
            }
        } catch (Throwable v0) {
            v0.printStackTrace();
        }
    }

    public static final class a {
        public int a;
        public int b;
        public String c;
        public int d;
        public String e;

        public a() {

        }

        public final JSONObject a() {
            JSONObject v0 = new JSONObject();
            try {
                if (this.a <= 0) {
                    return v0;
                }

                if (android.support.design.a.isTextEmpty(this.c)) {
                    return v0;
                }

                v0.put("id", this.a);
                v0.put("type", this.b);
                v0.put("obj", this.c);
                v0.put("from", this.d);
                v0.put("extra", this.e);
            } catch (Throwable v1) {
            }

            return v0;
        }

        public final String toString() {
            return "MessageObj{id=" + this.a + ", type=" + this.b + ", obj=\'" + this.c + '\'' + ", from=" + this.d + ", extra=\'" + this.e + '\'' + '}';
        }
    }
}

